package com.xiubai.appforpda.jack.utils;

import com.xiubai.appforpda.entity.SQLMainPamInventBean;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.LinkedHashMap;
import java.util.List;

/**
 * @author: r3562939
 * @version: V1.0
 * @project: AppForPda
 * @description: description
 * @date: 2018/11/17
 * @time: 18:05
 */
public class WebServiceDataUtils {
    // 获得数据的type
    public static final String GET_TYPE = "SMR01";
    // 领用申请
    public static final String POST_LY_TYPE = "LYSQ";
    // 借用申请
    public static final String POST_JY_TYPE = "JYSQ";
    // 归还
    public static final String POST_JYGH_TYPE = "JLGH";
    public static final String POST_SMPD = "SMPD";

    /**
     * 获取数据
     *
     * @param table_name
     * @param condition
     * @return
     */
    public static LinkedHashMap<String, String> getParameterData(String table_name, String condition) {
        LinkedHashMap<String, String> value = new LinkedHashMap<>();
        JSONArray jsonArray = new JSONArray();
        try {
            JSONObject json = new JSONObject();
            json.put("tablename", table_name);
            json.put("condition", condition);
            jsonArray.put(json);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        value.put("string", WebServiceDataUtils.GET_TYPE);
        value.put("string1", jsonArray.toString());
        return value;
    }


    /**
     * 领用表单
     *
     * @return
     */
    public static LinkedHashMap<String, String> postParameterData(String type, String billcode, String pamcode, String usercode, String audtcode, String date) {
        LinkedHashMap<String, String> value = new LinkedHashMap<>();
        JSONArray jsonArray = new JSONArray();
        try {
            JSONObject json = new JSONObject();
            json.put("billcode", billcode);
            // 测试数据
            json.put("equipcode", pamcode);
            json.put("user", usercode);
            json.put("agent", audtcode);
            json.put("date", date);
            jsonArray.put(json);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        value.put("string", type);
        value.put("string1", jsonArray.toString());
        return value;
    }

    /**
     * 领用表单
     *
     * @return
     */
    public static LinkedHashMap<String, String> postReturnParameterData(String type, String pamcode, String usercode, String audtcode, String date) {
        LinkedHashMap<String, String> value = new LinkedHashMap<>();
        JSONArray jsonArray = new JSONArray();
        try {
            JSONObject json = new JSONObject();
//            json.put("billcode", billcode);
            // 测试数据
            json.put("equipcode", pamcode);
            json.put("user", usercode);
            json.put("agent", audtcode);
            json.put("date", date);
            jsonArray.put(json);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        value.put("string", type);
        value.put("string1", jsonArray.toString());
        return value;
    }

    /**
     * 领用表单
     *
     * @return
     */
    public static LinkedHashMap<String, String> postCheckParameterData( SQLMainPamInventBean bean) {
        LinkedHashMap<String, String> value = new LinkedHashMap<>();
        JSONArray jsonArray = new JSONArray();
        try {
            JSONObject json = new JSONObject();
//            json.put("billcode", "JYSQ201811180002");
            // 测试数据
            json.put("billcode", bean.getBillcode());
            json.put("assetcode", bean.getAssetcode());
            json.put("assetname", bean.getAssetname());
            json.put("usercodeh", bean.getUsercodeh());
            json.put("loccodeh", bean.loccodeh);
            json.put("deptcodeh", bean.deptcodeh);
            json.put("stacodeh", bean.stacodeh);
            json.put("operator", bean.operator);
            json.put("bill_status", bean.bill_status);
            jsonArray.put(json);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        value.put("string", POST_SMPD);
        value.put("string1", jsonArray.toString());
        return value;
    }

    public static LinkedHashMap<String, String> postCheckParameterData(List<SQLMainPamInventBean> beans) {
        LinkedHashMap<String, String> value = new LinkedHashMap<>();
        JSONArray jsonArray = new JSONArray();
        try {
            for (SQLMainPamInventBean bean : beans) {
                JSONObject json = new JSONObject();
//            json.put("billcode", "JYSQ201811180002");
                // 测试数据
                json.put("billcode", bean.getBillcode());
                json.put("assetcode", bean.getAssetcode());
                json.put("assetname", bean.getAssetname());
                json.put("usercodeh", bean.getUsercodeh());
                json.put("loccodeh", bean.loccodeh);
                json.put("deptcodeh", bean.deptcodeh);
                json.put("stacodeh", bean.stacodeh);
                json.put("operator", bean.operator);
                json.put("bill_status", bean.bill_status);
                jsonArray.put(json);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        value.put("string", POST_SMPD);
        value.put("string1", jsonArray.toString());
        return value;
    }
}
